﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MoodleDesktop
{
    public partial class fmLogin : Form
    {
        private bool mousePressed = false;
        private Point diff = new Point(0, 0);

        public fmLogin()
        {
            InitializeComponent();
            this.AddEventHandler(this);
        }
        private void AddEventHandler(Control ctl)
        {
            ctl.MouseDown += new MouseEventHandler(ctl_MouseDown);
            ctl.MouseMove += new MouseEventHandler(ctl_MouseMove);
            ctl.MouseUp += new MouseEventHandler(ctl_MouseUp);
        }

        void ctl_MouseUp(object sender, MouseEventArgs e)
        {
            mousePressed = false;
        }

        void ctl_MouseMove(object sender, MouseEventArgs e)
        {
            if (mousePressed && (e.Button & MouseButtons.Left) != 0)
            {
                Point p = new Point(e.X, e.Y);
                p = PointToScreen(p);
                p.X -= diff.X;
                p.Y -= diff.Y;
                DesktopLocation = p;
            }    
        }

        void ctl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mousePressed = true;

                Point p = new Point(e.X, e.Y);
                p = PointToScreen(p);
                diff.X = p.X - DesktopLocation.X;
                diff.Y = p.Y - DesktopLocation.Y;
            }
        }

        private void btn_Thoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc chắn thoát khỏi chương trình ???", "Thông  báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.Close();
            }
        }

        private void btn_Thoat_MouseEnter(object sender, EventArgs e)
        {
            btn_Thoat.Image = Resource1.btn_ThoatHover;
        }

        private void btn_Thoat_MouseHover(object sender, EventArgs e)
        {
            btn_Thoat.Image = Resource1.btn_ThoatHover;
        }

        private void btn_Thoat_MouseLeave(object sender, EventArgs e)
        {
            btn_Thoat.Image = Resource1.btn_Thoat;
        }

        private void btn_DangNhap_Click(object sender, EventArgs e)
        {
            SelectingSource source = new SelectingSource();
            source.Show();
            //fmCalendar lich = new fmCalendar();
            //lich.Show();
           // lich.Parent = this;
            //Application.;
            //Application.Run(new fmCalendar());
            this.Visible = false;
            //this.Close();
        }

        private void btn_DangNhap_MouseEnter(object sender, EventArgs e)
        {
            btn_DangNhap.Image = Resource1.btn_DangNhapHover;
        }

        private void btn_DangNhap_MouseHover(object sender, EventArgs e)
        {
            btn_DangNhap.Image = Resource1.btn_DangNhapHover;
        }

        private void btn_DangNhap_MouseLeave(object sender, EventArgs e)
        {
            btn_DangNhap.Image = Resource1.btn_DangNhap;
        }
    }
}
